#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  4 18:39:12 2024

@author: Nicholas Drachman
"""

from advMSplot import *

''' Gly, Ala, Cys, Pro, Val, Phe '''

log_file_path = 'Fig 2/b/Gly_Ala_Cys_Pro_Val_Phe/MAY 18 2018 9-14.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/b/Gly_Ala_Cys_Pro_Val_Phe/MAY 18 2018 9-14.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/b/Gly_Ala_Cys_Pro_Val_Phe/ivpt11.tsv' # ivpt file path for glutathione (GSH) here

# Process glutathione spec
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)


# Proline 
scan_start, scan_end = 10000,13000
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('PRO')


# Alanine
scan_start, scan_end = 16800,18200
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('ALA')


# Cystiene
scan_start, scan_end = 21800,23000
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('CYS')


# Phenylalanine
scan_start, scan_end = 25000,27000
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('PHE')



# Valine
scan_start, scan_end = 32000,34000
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('VAL')



# Glycine
scan_start, scan_end = 39000,43000
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[300:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('Gly')




''' Ser_Met_Trp '''

log_file_path = 'Fig 2/b/Ser_Met_Trp/JUL 27 2017 9-28.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/b/Ser_Met_Trp/JUL 27 2017 9-28.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/b/Ser_Met_Trp/ivpt.tsv' # ivpt file path for glutathione (GSH) here

tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)


# Serine
scan_start, scan_end = 11500,12500
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[300:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('SER')


# Methionine
scan_start, scan_end = 14500,18500
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[300:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('MET')


# Tryptophan
scan_start, scan_end = 36500,37550
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[1000:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('TRP')




''' Thr_Leu '''

log_file_path = 'Fig 2/b/Thr_Leu/MAY 18 2018 17-01.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/b/Thr_Leu/MAY 18 2018 17-01.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/b/Thr_Leu/ivpt12.tsv' # ivpt file path for glutathione (GSH) here

# Process glutathione spec
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)


# Leucine
scan_start, scan_end =  6000, 6600
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('LEU')


# Threonine
scan_start, scan_end =  8500, 9300
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('THR')


''' Arg_Lys '''

log_file_path = 'Fig 2/b/Arg_Lys/JAN 23 2018 15-26.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/b/Arg_Lys/JAN 23 2018 15-26.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/b/Arg_Lys/ivpt15.tsv' # ivpt file path for glutathione (GSH) here

# Process glutathione spec
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)


# Arginine
scan_start, scan_end =  9500,10500
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)


mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('ARG')


# Lysine
scan_start, scan_end =  19000, 22000
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('LYS')





''' His '''

log_file_path = 'Fig 2/b/His/JAN 21 2018 15-52.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/b/His/JAN 21 2018 15-52.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/b/His/ivpt09.tsv' # ivpt file path for glutathione (GSH) here

# Process glutathione spec
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)



scan_start, scan_end =  5300, 8300
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('HIS')


''' Asn '''


log_file_path = 'Fig 2/b/Asn/AUG 4 2017 17-39.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/b/Asn/AUG 4 2017 17-39.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/b/Asn/ivpt.tsv' # ivpt file path for glutathione (GSH) here

# Process glutathione spec
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)


scan_start, scan_end =  23500, 28000
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('ASN')




''' Gln '''



log_file_path = 'Fig 2/b/Gln/MAY 31 2017 9-29.log' # log file path for oglutathione (GSH) here
cdf_file_path = 'Fig 2/b/Gln/MAY 31 2017 9-29.cdf' # CDF file path for glutathione (GSH) here
tsv_file_path = 'Fig 2/b/Gln/ivpt.tsv' # ivpt file path for glutathione (GSH) here

# Process glutathione spec
tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)


scan_start, scan_end = 11300, 14500
spec = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)

mz = spec[0]
A = spec[1]

N = 35
mzsmooth = np.convolve(mz,np.ones(N)/N, mode = 'same')
Asmooth = np.convolve(A,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth[0:-N//2],Asmooth[0:-N//2]/np.max(Asmooth[500:]))
ax.set_xlim(50,350)
ax.set_ylim(0,1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('intensity (arb.)')
ax.tick_params(direction = 'in')
ax.set_title('GLN')





